package com.mingmen.canting.chushizhang;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.mingmen.canting.R;
import com.mingmen.canting.activity.LoginActivity;
import com.mingmen.canting.activity.YuCaiGouDanActivity;
import com.mingmen.canting.base.BaseBean;
import com.mingmen.canting.definerecycleview.OnItemClickListener;
import com.mingmen.canting.definerecycleview.SwipeRecyclerView;
import com.mingmen.canting.defineview.ClearEditText;
import com.mingmen.canting.dialog.ButtomDialogView;
import com.mingmen.canting.flycotablelayout.flyco.tablayout.widget.MsgView;
import com.mingmen.canting.fragment.BaseFragment;
import com.mingmen.canting.http.callback.StringCallback;
import com.mingmen.canting.httpconfig.HttpResponse;
import com.mingmen.canting.model.ChushiShenHeModel;
import com.mingmen.canting.model.DingDanZhongLeiModel;
import com.mingmen.canting.model.PurCountModel;
import com.mingmen.canting.model.ShenHeModel;
import com.mingmen.canting.tabuse.ui.SimpleCardFragment;
import com.mingmen.canting.util.DateUtils;
import com.mingmen.canting.util.GsonUtil;
import com.mingmen.canting.util.MyStringUtils;
import com.mingmen.canting.util.SharePreferenceUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import okhttp3.Call;
import okhttp3.Response;

@SuppressLint("ValidFragment")
public class CaiGouNewShenHeFragment extends BaseFragment implements ChuShiDingShenAdapter.OnItemClickListener {


    Unbinder unbinder;

    String mTitle;

    public static CaiGouNewShenHeFragment getInstance(String title) {
        CaiGouNewShenHeFragment sf = new CaiGouNewShenHeFragment();
        sf.mTitle = title;
        return sf;
    }


    String token;
    ButtomDialogView bottomSheetDialog;
    @BindView(R.id.text_category)
    TextView text_category;
    @BindView(R.id.text_order)
    TextView text_order;

    ChuShiOrderFragment dingDanListFragment;
    ZhongLeiFragment zhongLeiFragment;
    @BindView(R.id.layout_dingdan)
    LinearLayout layout_dingdan;
    List<String> cancelFlag = new ArrayList<>();
    @Override
    public View initView() {
//        return null;
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.fr_caigou_new_shenhe, null);
        unbinder = ButterKnife.bind(this, view);
        initFragment1();

        return view;
    }


    //显示第一个fragment
    private void initFragment1() {

        FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
        if (dingDanListFragment == null) {
            dingDanListFragment = new ChuShiOrderFragment();
            transaction.add(R.id.main_frame_layout, dingDanListFragment);
        }
        //隐藏所有fragment
        hideFragment(transaction);
        //显示需要显示的fragment
        transaction.show(dingDanListFragment);
        transaction.commit();
    }

    //显示第二个fragment
    private void initFragment2() {

        FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
        if (zhongLeiFragment == null) {
            zhongLeiFragment = new ZhongLeiFragment();
            transaction.add(R.id.main_frame_layout, zhongLeiFragment);
        }
        //隐藏所有fragment
        hideFragment(transaction);
        //显示需要显示的fragment
        transaction.show(zhongLeiFragment);
        transaction.commit();
    }

    private void hideFragment(FragmentTransaction transaction) {
        if (dingDanListFragment != null) {
            transaction.hide(dingDanListFragment);
        }
        if (zhongLeiFragment != null) {
            transaction.hide(zhongLeiFragment);
        }

    }

    @Override
    public void initData() {


    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();

    }

    @OnClick({R.id.text_category,  R.id.text_order})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.text_category:
                layout_dingdan.setBackground(getActivity().getResources().getDrawable(R.mipmap.dingdan));
//                ding_zhogn = true;
            /*    flag = 0;
                layout_search.setVisibility(View.GONE);
                view_zhan.setVisibility(View.VISIBLE);
                btn_AuditPass.setVisibility(View.VISIBLE);
                mRecyclerView.setVisibility(View.VISIBLE);
                mRecyclerView1.setVisibility(View.GONE);*/
                initFragment1();
                break;
            case R.id.text_order:
                initFragment2();
                layout_dingdan.setBackground(getActivity().getResources().getDrawable(R.mipmap.zhonglei));
                break;
        }
    }

    @Override
    public void onItemClickListener(View view, int parentPosition, int position, List<ChushiShenHeModel.DataBean> groupList, List<ChushiShenHeModel.DataBean.DetailsBean> memberList) {

    }
}